﻿using System;
using System.Collections.Generic;
using OpenGL;

namespace System
{
	public partial struct Line3G
	{
		void DrawIt(V3G V1, V3G V2, int Iteration, bool Full, bool Twoside)
		{
			if (Iteration <= 0)
			{
				if (Full)
					new Line3D(V1, V2).GLDrawFull();
				else
					if (Twoside)
						new Line3D(V1, V2).GLDraw();
					else
						((V3D)V1).GLDraw();
			}
			else
			{
				V3G C = V3G.Interpolate(V1, V2, 0.5);
				DrawIt(V1, C, Iteration - 1, Full, Twoside);
				DrawIt(C, V2, Iteration - 1, Full, Twoside);
			}
		}
		public static void DS(V3G P1, V3G P2, double MaxL, int N, bool DrawLast)
		{
			if ((P1 - P2).Length < MaxL)
			{
				((V3D)P1).GLDraw();
			}
			else
			{
				DS(P1, V3G.Interpolate(P1, P2, 0.5), MaxL, N + 1, DrawLast);
				DS(V3G.Interpolate(P1, P2, 0.5), P2, MaxL, N + 1, DrawLast);
			}
			if (N == 0 && DrawLast)
				((V3D)P2).GLDraw();
		}
		public void DrawOnSphere()
		{
			GL.glBegin(GL.GL_LINE_STRIP);
			DS(A, B, 50000, 0, true);
			GL.glEnd();
		}
		public void GLDraw(bool Full, bool TwoSide)
		{
			DrawIt(A, B, 3, Full, TwoSide);
		}
	}
}